import {Component, OnInit, Input} from '@angular/core'
import {DialogService} from 'primeng/primeng'
import {QkProfileComponent} from './profile.component';
import {QkProfileService} from './profile.service';
import {Router} from '@angular/router';
import {
    ConfirmationService,
    MenuItem,
    SplitButtonModule,
    PanelMenuModule,
    MenubarModule,
} from 'primeng/primeng';

@Component({
    selector: 'qk-profile-icon',
    templateUrl: './profile-icon.component.html',
    styleUrls: ['./profile-icon.component.scss'],
    providers: [QkProfileService]
})
export class QkProfileIconComponent implements OnInit {
    @Input()
    style: any;
    userName: string = "";
    unitName: string = "";
    dateNow: string = "";
    dateWeek: string = "";
    src: string = "/assets/images/desktop/note.png"; //默认头像


    constructor(
        public dialogService: DialogService,
        public profileService: QkProfileService,
        private confirmationService: ConfirmationService,
        private router: Router,
    ) {
    }

    ngOnInit() {
        let now = new Date();
        this.dateNow = now.getFullYear() + "年" + (now.getMonth() + 1) + "月" + now.getDate() + "日";
        this.dateWeek = "星期" + "日一二三四五六".charAt(now.getDay());

        this.profileService.showAvatar().subscribe(data => {
            if (data != null && data != "") {
                this.src = "data:image/jpeg;base64," + data;
            }
        });
        let currentHumanInfo = JSON.parse(localStorage.getItem("currentHumanInfo"));
        this.userName = currentHumanInfo.humanName ;
        this.unitName =  currentHumanInfo.unitName;
    }


    showUserProfile() {
        let pDialog = this.dialogService.open(QkProfileComponent, {
            showHeader: false,
            width: '977px',
            contentStyle: {'height': '600px', 'padding': '0'}
        });
        pDialog.onClose.subscribe(src => $(".profile-icon-image").attr('src', src));
    }

}
